package com.example.uridemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {

    private static final int FILECHOOSER_RESULTCODE = 0xf1;
    ImageView button1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //intiURI();
        //intiData();
        intiShare();
    }
    public   void intiURI(){
        Intent it=new Intent(Intent.ACTION_VIEW);
        Uri uri=Uri.parse("tel:10086");
        it.putExtra("sms_body","信息内容");
        it.setType("vnd.android.dir/mms-sms");
        startActivity(it);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (RESULT_OK == resultCode && requestCode == FILECHOOSER_RESULTCODE) {
            Uri uri = data == null ? null : data.getData();
            button1.setImageURI(uri);
        }

    }

    private void intiData(){
        Button button=findViewById(R.id.choose_image);
        button1=findViewById(R.id.share_image);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setType("image/*");
                startActivityForResult(Intent.createChooser(intent,"File Chooser"),FILECHOOSER_RESULTCODE);
            }
        });
    }

    private void intiShare(){
        Intent intent=getIntent();
        String action=intent.getAction();
        if(Intent.ACTION_VIEW.equals(action)){
            Uri uri=intent.getData();
            if (uri!=null){
                String host=uri.getHost();
                String dataString=intent.getDataString();
                String id=uri.getQueryParameter("id");
                String path=uri.getPath();
                String path1=uri.getEncodedPath();
                String queryString=uri.getQuery();
            }
        }
        Uri uri=Uri.parse("google:www.google.com/share？id=1");
        Intent intent1=new Intent(null,uri);
        startActivity(intent1);
    }

}